package cn.stylefeng.guns.modular.trip.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;

import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;

import cn.stylefeng.guns.modular.system.model.Medicaltype;
import cn.stylefeng.guns.modular.system.model.Triptype;
import cn.stylefeng.guns.modular.trip.service.ITriptypeService;

/**
 * 旅游期刊控制器
 *
 * @author fengshuonan
 * @Date 2020-06-21 00:52:13
 */
@Controller
@RequestMapping("/triptype")
public class TriptypeController extends BaseController {

    private String PREFIX = "/trip/triptype/";

    @Autowired
    private ITriptypeService triptypeService;

    /**
     * 跳转到旅游期刊首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "triptype.html";
    }

    /**
     * 跳转到添加旅游期刊
     */
    @RequestMapping("/triptype_add")
    public String triptypeAdd() {
        return PREFIX + "triptype_add.html";
    }

    /**
     * 跳转到修改旅游期刊
     */
    @RequestMapping("/triptype_update/{triptypeId}")
    public String triptypeUpdate(@PathVariable Integer triptypeId, Model model) {
        Triptype triptype = triptypeService.selectById(triptypeId);
        model.addAttribute("item",triptype);
        LogObjectHolder.me().set(triptype);
        return PREFIX + "triptype_edit.html";
    }

    /**
     * 获取旅游期刊列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	EntityWrapper<Triptype> wrapper = new EntityWrapper<Triptype>();
    	wrapper.like("goods_name", condition).or()
    	.like("id", condition);
        return triptypeService.selectList(wrapper);
    }

    /**
     * 新增旅游期刊
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Triptype triptype) {
        triptypeService.insert(triptype);
        return SUCCESS_TIP;
    }

    /**
     * 删除旅游期刊
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer triptypeId) {
        triptypeService.deleteById(triptypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改旅游期刊
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Triptype triptype) {
        triptypeService.updateById(triptype);
        return SUCCESS_TIP;
    }

    /**
     * 旅游期刊详情
     */
    @RequestMapping(value = "/detail/{triptypeId}")
    @ResponseBody
    public Object detail(@PathVariable("triptypeId") Integer triptypeId) {
        return triptypeService.selectById(triptypeId);
    }
    @InitBinder
   	public void initBinder(WebDataBinder binder) {
   	    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   	    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));        
   	}
}
